#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V,maxx,summ;
int d[100010],v[100010],a;
int p[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a;
        }
        for(int j=1;j<=m;j++){
            cin>>p[j];
            maxx=max(maxx,p[j]);
        }
        for(int i=1;i<=n;i++){
            if(d[i]<=maxx){
                if(v[i]>V) summ++;
            }
        }
        cout<<summ<<" "<<m-1<<endl;
        summ=0;maxx=0;

    }
return 0;}
